package com.biomatch.config;

//import com.biomatch.service.SysLogService;
import lombok.extern.slf4j.Slf4j;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

@Aspect
@Configuration
@Slf4j
public class AopConfig {

//    @Autowired
//    private SysLogService sysLogService;

    //前置通知
    //指定该方法是前置通知，并制定切入点
    @Before("execution(* com.biomatch.service.impl.*ServiceImpl.*(..))")
    public void before() {
        //前置通知
    }

    //后置通知
    @AfterReturning("execution(* com.biomatch.service.impl.*ServiceImpl.*(..))")
    public void afterReturning() {
        //后置通知（如果出现异常不会调用）
    }

    //环绕通知
    @Around("execution(* com.biomatch.controller.*Controller.*(..)))")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
/*        Object[] args = pjp.getArgs();
        Signature signature = pjp.getSignature();
        Object proceed = pjp.proceed();
        if (args.length != 0) {
            sysLogService.save(args, signature, proceed);
        }
        return proceed;*/
        return  pjp.proceed();
    }

    //异常通知
    @AfterThrowing("execution(* com.biomatch.service.impl.*ServiceImpl.*(..))")
    public void afterException() {
        //异常通知
    }

    //后置通知
    @After("execution(* com.biomatch.service.impl.*ServiceImpl.*(..))")
    public void after() {
        //后置通知（出现异常也会调用）
    }
}